package com.ficus.road.maintain.core.interceptor;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xiawen yang
 * @date 2022/4/1 下午9:03
 */
//@Configuration
public class MyHandleExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        try {
            response.addHeader("Content-Type", "text/html; charset=UTF-8");
            response.getWriter().append("自定义异常处理!!! \n").append(ex.getMessage()).flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;


//        ModelAndView mv = new ModelAndView();
//        // 判断不同异常类型，做不同视图跳转
//        if (ex instanceof Exception) {
//            mv.setViewName("error1");
//        }
//        mv.addObject("error", ex.toString());
//        return mv;
    }
}

